from pydantic_settings import BaseSettings
from typing import List
import os

class Settings(BaseSettings):
    # 应用配置
    APP_NAME: str = "全栈应用模板"
    VERSION: str = "1.0.0"
    DEBUG: bool = True
    
    # 数据库配置
    DATABASE_URL: str = ""
    DB_HOST: str = "db"
    DB_PORT: int = 5432
    DB_USER: str = "postgres_user"
    DB_PASSWORD: str = "postgres_pass"
    DB_NAME: str = "fullstack_db"
    
    # CORS 配置
    ALLOWED_ORIGINS: str = "http://localhost:3000"
    
    class Config:
        env_file = ".env"
        case_sensitive = True
    
    def get_database_url(self) -> str:
        """获取数据库连接URL"""
        if self.DATABASE_URL:
            return self.DATABASE_URL
        return f"postgresql://{self.DB_USER}:{self.DB_PASSWORD}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"
    
    def get_allowed_origins(self) -> List[str]:
        """获取允许的域名列表"""
        return [origin.strip() for origin in self.ALLOWED_ORIGINS.split(",")]

# 全局设置实例
settings = Settings() 